<template>
    <div class="Dog">
        <div>
            <ul>
                <li v-for="val, i in obj" :key="i">
                    <img :src='val.img' alt="">
                    <p @click="RgbCol(val.id)" ref="pG">{{ val.name }}</p>
                </li>
            </ul>
        </div>
    </div>
</template>

<script>
import { nextTick } from 'vue';
export default {
    name: "DlgIndex",
    data() {
        return {
            obj: [
                {
                    id:0,
                    name: '这是一个可怜的宠物',
                    img: 'http://192.168.0.5:8080/img/dog.9cedc79b.png'
                },
                {
                    id:1,

                    name: '这是一个可怜的宠物',
                    img: 'http://192.168.0.5:8080/img/dog.9cedc79b.png'
                },
                {
                    id:2,
                    name: '这是一个可怜的宠物',
                    img: 'http://192.168.0.5:8080/img/dog.9cedc79b.png'
                },
                {
                    id:3,
                    name: '这是一个可怜的宠物',
                    img: 'http://192.168.0.5:8080/img/dog.9cedc79b.png'
                },
                {
                    id:4,

                    name: '这是一个可怜的宠物',
                    img: 'http://192.168.0.5:8080/img/dog.9cedc79b.png'
                },
                {
                    id:5,
                    name: '这是一个可怜的宠物',
                    img: 'http://192.168.0.5:8080/img/dog.9cedc79b.png'
                },
            ]

        }
    },
    methods: {
        sj(){
            function fn(a,b){
                return Math.floor(Math.random()*(b-a+1))+a
            }
            let obj = []
            for(var i=1;i<=4;i++){
                let a = fn(0,600)
                obj.push(a)
            }
            // console.log(obj.join(','));
            return obj.join(',')
        },
        RgbCol(v) {
            console.log('a');
            let p = this.$refs.pG
            console.log(p[v]);
            // 随机数
            let sj = this.sj()
            p[v].style.backgroundColor=`rgba(${sj})`

            
        }
    },
}
</script>

<style>
ul {
    width: 100%;
    height: 100%;
}

li {
    width: 200px;
    height: 200px;
    /* background-color: bisque; */
    float: left;
    border: solid 1px rgb(0, 0, 0);
}

img {
    width: 100%;
    height: 80%;
}

p {
    text-align: center;
    line-height: 10px;
}
</style>